package com.dingding.service.user.facade.car;

import javax.annotation.Resource;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.dingding.common.core.base.dto.FacadeResult;
import com.dingding.common.core.exception.bussiness.BussinessException;
import com.dingding.facade.user.dto.car.ResGetCarBrands;
import com.dingding.facade.user.dto.car.ResGetCarModels;
import com.dingding.facade.user.service.car.ICarBrandModelFacade;
import com.dingding.service.user.core.car.CarBrandModelDao;

/**
 * @Description:车辆品牌和车型的服务类
 * @author fengshuonan
 * @date 2016年10月25日 下午5:03:24
 * @version 叮叮搭车
 * @since 2.4
 */
@Component("carBrandModelFacade")
public class CarBrandModelFacadeImpl implements ICarBrandModelFacade{
	
	private Logger log = Logger.getLogger(this.getClass());
	
	@Resource(name = "carBrandModelDao")
	private CarBrandModelDao carBrandModelDao;

	/**
	 * @Description:所有的车辆品牌和车辆型号信息入库
	 * @author fengshuonan
	 * @since 2.4
	 */
	@Override
	public void fetchToDb(){
		try {
			this.carBrandModelDao.fetchToDb();
		} catch (Exception e) {
			return;
		}
	}
	
	/**
	 * @Description:获取新增车辆的品牌
	 * @author fengshuonan
	 * @since 2.4
	 */
	@Override
	public FacadeResult<ResGetCarBrands> getCarBrands(Integer currentCusCarBrandNum) {
		FacadeResult<ResGetCarBrands> result = new FacadeResult<ResGetCarBrands>();
		try {
			ResGetCarBrands carBrands = this.carBrandModelDao.getCarBrands(currentCusCarBrandNum);
			result.setObject(carBrands);
		} catch (BussinessException e) {
			result.setCode(e.getCode());
			result.setMessage(e.getErrorMessage());
		} catch (Exception e){
			log.error("数据库异常！",e);
			result.setCode(500);
			result.setMessage("服务器异常！");
		}
		return result;
	}

	/**
	 * @Description:获取车辆品牌所对应的所有型号
	 * @param carBrandId
	 * @author fengshuonan
	 * @since 2.4
	 */
	@Override
	public FacadeResult<ResGetCarModels> getCarModels(Integer carBrandId) {
		FacadeResult<ResGetCarModels> result = new FacadeResult<ResGetCarModels>();
		try {
			ResGetCarModels carModels = this.carBrandModelDao.getCarModels(carBrandId);
			result.setObject(carModels);
		} catch (BussinessException e) {
			result.setCode(e.getCode());
			result.setMessage(e.getErrorMessage());
		} catch (Exception e){
			log.error("数据库异常！",e);
			result.setCode(500);
			result.setMessage("服务器异常！");
		}
		return result;
	}
}
